

class MovieItemListModel {
  List<MovieItem> data;

  MovieItemListModel({this.data});

  MovieItemListModel.fromJson(Map<String, dynamic> json) {
    if (json['data'] != null) {
      data = new List<MovieItem>();
      json['data'].forEach((v) {
        data.add(new MovieItem.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    if (this.data != null) {
      data['data'] = this.data.map((v) => v.toJson()).toList();
    }
    return data;
  }
}

class MovieItem {
  int rank;
  List<String> directors;
  String rate;
  int coverX;
  String star;
  String title;
  String url;
  List<String> casts;
  String cover;
  String id;
  int coverY;

  MovieItem(
      {this.directors,
      this.rate,
      this.coverX,
      this.star,
      this.title,
      this.url,
      this.casts,
      this.cover,
      this.id,
      this.coverY});

  int counter = 1;

  MovieItem.fromJson(Map<String, dynamic> json) {
    this.rank = counter++;
    this.directors = json['directors'].cast<String>();
    this.rate = json['rate'];
    this.coverX = json['cover_x'];
    this.star = json['star'];
    this.title = json['title'];
    this.url = json['url'];
    this.casts = json['casts'].cast<String>();
    this.cover = json['cover'];
    this.id = json['id'];
    this.coverY = json['cover_y'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['directors'] = this.directors;
    data['rate'] = this.rate;
    data['cover_x'] = this.coverX;
    data['star'] = this.star;
    data['title'] = this.title;
    data['url'] = this.url;
    data['casts'] = this.casts;
    data['cover'] = this.cover;
    data['id'] = this.id;
    data['cover_y'] = this.coverY;
    return data;
  }
}



// class Person {
//   String name;
//   String avatarURL;

//   Person.fromMap(Map<String, dynamic> json) {
//     this.name = json["name"];
//     this.avatarURL = json["avatars"]["medium"];
//   }
// }

// class Actor extends Person {
//   Actor.fromMap(Map<String, dynamic> json): super.fromMap(json);
// }

// class Director extends Person {
//   Director.fromMap(Map<String, dynamic> json): super.fromMap(json);
// }

// int counter = 1;

// class MovieItem {
//   int rank;
//   String imageURL;
//   String title;
//   String playDate;
//   double rating;
//   List<String> genres;
//   List<Actor> casts;
//   Director director;
//   String originalTitle;

//   MovieItem.fromMap(Map<String, dynamic> json) {
//     this.rank = counter++;
//     this.imageURL = json["images"]["medium"];
//     this.title = json["title"];
//     this.playDate = json["year"];
//     this.rating = json["rating"]["average"];
//     this.genres = json["genres"].cast<String>();
//     this.casts = (json["casts"] as List<dynamic>).map((item) {
//       return Actor.fromMap(item);
//     }).toList();
//     this.director = Director.fromMap(json["directors"][0]);
//     this.originalTitle = json["original_title"];
//   }
// }